package avicit.bdp.dms.oauth2.token;

import avicit.bdp.core.constant.Constants;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.util.Date;

/**
 * TODO
 *
 * @author xugb
 * @date 2024/4/15 9:31
 */

public class AccessToken  implements Serializable {
    public static final String BEARER_TYPE = "Bearer";
    private String accessToken;
    private String internalToken;
    private String refreshToken;
    private String expireTime;
    private String refreshTime;
    @JsonFormat(timezone = "GMT+8", pattern = Constants.YYYYMMDDHHMMSS)
    private Date createTime;

    public AccessToken() {
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getExpireTime() {
        return this.expireTime;
    }

    public void setExpireTime(String expireTime) {
        this.expireTime = expireTime;
    }

    public String getRefreshTime() {
        return this.refreshTime;
    }

    public void setRefreshTime(String refreshTime) {
        this.refreshTime = refreshTime;
    }

    public String getAccessToken() {
        return this.accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getRefreshToken() {
        return this.refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public String getInternalToken() {
        return this.internalToken;
    }

    public void setInternalToken(String internalToken) {
        this.internalToken = internalToken;
    }

    @JsonIgnore
    public long currentTokenExpiredSeconds() {
        long time = this.createTime.getTime() + Long.parseLong(this.expireTime) * 1000L;
        return (time - System.currentTimeMillis()) / 1000L;
    }
}

